<template>
  <div class="listItem" @click="godetail">
    <div class="title">
      <h3>{{ item.title }}</h3>
      <div class="HB">
        <img src="../../assets/images/image/hdpi/h_currency.png" alt="" />
        <span>{{ item.amount }}</span>
      </div>
    </div>
    <p class="time">{{ releaseTime }}</p>
    <div class="detail">{{ item.detail }}</div>
    <ul class="collect">
      <li>
        <span>建议</span>
        <span>{{ item.commentNum }}</span>
      </li>
      <li>
        <span>收藏</span>
        <span>{{ item.collectionNum }}</span>
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, defineProps,defineEmits } from 'vue';
// import formData from '@/utils/formData.js';

// Define the props for the component
const props = defineProps<{
  item: {
    title: string;
    amount: number;
    releaseTime: string;
    detail: string;
    commentNum: number;
    collectionNum: number;
  };
}>();
const emit = defineEmits<{
  (event: 'todetail'): void; // Declare the 'todetail' event
}>();
const releaseTime = ref("");

// Function to handle detail navigation
const godetail = () => {
   emit("todetail");
};

// Format the release time on component mount
onMounted(() => {
  const date = new Date(props.item.releaseTime);
  // releaseTime.value = formData(date, "yyyy-MM-dd hh:mm");
});
</script>

<style lang="scss" scoped>
.listItem {
  width: 100%;
  margin-top: 4px;
  padding: 20px;
  box-sizing: border-box;
  background-color: white;

  .title {
    display: flex;
    justify-content: space-between;

    h3 {
      font-size: 16px;
      color: #333;
    }

    .HB {
      display: flex;
      justify-content: space-around;
      align-items: center;

      img {
        width: 20px;
        height: 20px;
      }

      span {
        margin-left: 6px;
        font-size: 13px;
        color: #d92109;
      }
    }
  }

  .time {
    font-size: 10px;
    color: #333;
    margin: 10px 0 8px 0;
  }

  .detail {
    font-size: 12px;
    color: #333;
    line-height: 20px;
  }

  .collect {
    display: flex;
    justify-content: flex-end; /* Changed to flex-end for right alignment */
    margin-top: 16px;
    font-size: 10px;
    color: #333;

    li {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-left: 14px;

      span {
        margin-left: 6px;
      }
    }
  }
}
</style>
